package com.cre_drt;

import android.R;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

@SuppressLint("ValidFragment")
public class DialogBox extends DialogFragment {

	private final String errorMessage;
	private final boolean startNewActivity;
	private final Context context;

	public DialogBox(String errorMessage, boolean startNewActivity, Context context) {
		this.errorMessage = errorMessage;
		this.startNewActivity = startNewActivity;
		this.context = context;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the Builder class for convenient dialog construction
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setMessage(errorMessage).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				if (startNewActivity == true) {
					Intent GLCIntent = new Intent(context, TaskSelectionScreen.class);
					GLCIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(GLCIntent);
				}
			}
		});
		// Create the AlertDialog object and return it
		return builder.create();
	}
}
